package com.example.hms.controller;


import com.example.hms.entity.User;
import com.example.hms.service.UserServive;
import com.example.hms.ulit.Result;
import com.example.hms.ulit.ResultSubmit;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;


@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserServive userServive;
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result login(@RequestBody Map<String,String> map, HttpServletRequest request) {
        String userId=map.get("userId");
        String password=map.get("userPassword");
        if (userId == null || password == null || userId.equals(" ") || password.isEmpty()) {
            return ResultSubmit.error("输入参数不全");
        }
        return userServive.login(userId,password,request);
    }
    @RequestMapping(value = "/login2",method = RequestMethod.GET)
    public Result login2( String userId,String password, HttpServletRequest request) {
        return userServive.login(userId,password,request);
    }
    @RequestMapping(value = "/info",method = RequestMethod.POST)
    public Result info( HttpServletRequest request) {
        return userServive.info(request);
    }

    @RequestMapping(value = "/logout",method = RequestMethod.POST)
    public Result logout( HttpServletRequest request) {
        HttpSession session=request.getSession();
        session.setAttribute("token",null);
        session.setAttribute("userId",null);
        return ResultSubmit.success("退出成功");
    }
    @RequestMapping(value = "/selectAllUser",method = RequestMethod.GET)
    public Result selectAllUser( String userId, String userName, String roleName) {
        return userServive.selectAllUser(userId,userName,roleName);
    }
    @RequestMapping(value = "/insert",method = RequestMethod.GET)
    public Result insert(User user) {
        return userServive.insert(user);
    }
    @RequestMapping(value = "/update",method = RequestMethod.GET)
    public Result update(User user) {
        return userServive.update(user);
    }
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result delete(String userId)  {
        return userServive.delete(userId);
    }

}
